package com.zoke.support.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.BaseAdapter;
import android.widget.ListView;

/**
 * 嵌套内在ScrollView内使用的ListView
 * 
 * @author JackWu
 * @version
 * @date 2014-10-21
 * @_QQ_ 651319154
 */
public class ScrollListView extends ListView {
	public ScrollListView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	public ScrollListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public ScrollListView(Context context) {
		super(context);
	}

	@Override
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

		/**
		 * 解决ScrollView与ListView的嵌套问题
		 */
		int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
				MeasureSpec.AT_MOST);
		super.onMeasure(widthMeasureSpec, expandSpec);
	}

	/** 解决listView和ScrollView嵌套使用导致的ScrollView滑动到ListView对应位置的问题 **/
	public void setAdapter(BaseAdapter adapter, ReboundScrollView scrollView) {
		setAdapter(adapter);
		if (null != scrollView)
			// 将位置滑动至顶端
			scrollView.smoothScrollTo(0, 0);
	}

}
